
export default   class   JsrLoad {

    run(name,obj,value,type){

        let res;
        let Dx= qguan("dx")
        let root= qguan("root")
        if(name){

            return new Promise(resolve => {
                let data=root.findData(name)

                data.then(   (data1)=>{
                    let dx =new Dx();
                    dx.loadData(data1)
                    let aopFactory=qguan("aopFactory")
                    let code=  dx.findFile(name,obj,value);
                    if(code){
                        let txt=  code.rxToTxt()
                        let resObj=     aopFactory.createCodeObj(name,value,txt)
                        resolve(resObj);
                    }else {
                        throw name+'包没有找到'+value +'文件';
                    }
                } )
            })

        }else { //根据文件扫描
            //获取所以jsr包
            return new Promise(resolve => {
                let   jsrs=root.findJsrs();
                let res=[];
                for(let i=0;i<jsrs.length;i++){
                    let data=jsrs[i];
                    let dx =new Dx();
                    dx.loadData(data1)
                    let aopFactory=qguan("aopFactory")
                    let code=  dx.findFile(name,obj,value);
                    if(code){
                        let txt=  code.rxToTxt()
                            let resObj=     aopFactory.createCodeObj(name,value,txt)
                            res.push(resObj);
                        }
                        resolve( res);
                    }
            })


        }
    }
}
